extends TextureButton

var is_dragging = false

func _ready():
	set_process_input(true)

func _gui_input(event):
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
		if event.pressed :
				is_dragging = true
				$"..".modulate = Color(2, 2, 2, 1)
				grab_focus()  # 抓取焦点，以防止其他控件捕获鼠标事件
				var k = randi()%2 #出牌随机数
				var position_offset = randi() % 100 + 20
				var sce
				if k == 0:
					sce = preload("res://场景/小卡片/上顶.tscn").instantiate()
					sce.add_to_group("top")
				else:
					sce = preload("res://场景/小卡片/下底.tscn").instantiate()
					sce.add_to_group("bottom")
				sce.global_position = $"..".global_position
				sce.get_child(2).last_location = $"..".global_position + Vector2.RIGHT * position_offset
				sce.add_to_group("card")
				$"..".get_parent().add_child(sce)
		else:
			if is_dragging:
				is_dragging = false
				$"..".modulate = Color(1, 1, 1, 1)
				release_focus()
				# 处理放下逻辑，这里可以执行您需要的操作

func _process(delta):
	pass

